package com.zy.explore.gateway.config;

import com.zy.explore.gateway.handler.HystrixFallbackHandler;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;

/**
 * 网关路由器配置
 *
 * @author ZY
 * @date 2021/06/12
 */
@Slf4j
@Configuration
@AllArgsConstructor
public class GatewayRoutersConfig {

    private final HystrixFallbackHandler hystrixFallbackHandler;

    /**
     * 路由器的功能
     *
     * @return {@link RouterFunction<?>}
     */
    @Bean
    public RouterFunction<?> routerFunction() {
        return RouterFunctions.route(
                RequestPredicates.path("/fallback").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), hystrixFallbackHandler);

    }

}
